Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / ble / src / androidMain / kotlin / org / meshtastic / core / ble / KableGattCacheRefresh.kt

Displaying Raw • Download

core/ble/src/androidMain/kotlin/org/meshtastic/core/ble/KableGattCacheRefresh.kt 01cd54907d62cd90913d3d071b6bc240cae365ef (01cd5490) Text, 3.49 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ble

Tff7b72import T7ee787android.bluetooth.BluetoothGatt
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787com.juul.kable.Peripheral
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow

Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffReturnCountTa5d6ff"Tb4b4b4)
Tff7b72internal Tff7b72actual Tff7b72fun Te6edf3PeripheralTb4b4b4.Td2a8ffrefreshGattCacheTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tb4b4b4{
T8b949e// Direct 2-hop reflection on Kable 0.43.1 internals.
T8b949e// Path: BluetoothDeviceAndroidPeripheral.connection (MutableStateFlow<Connection?>) → .value → Connection.gatt
T8b949e// Re-verify field names on Kable version bumps.
Tff7b72val Te6edf3gatt Tff7b72=
Tff7b72try Tb4b4b4{
Te6edf3extractBluetoothGattTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffrefreshGattCache: BluetoothGatt extraction failed (Tffd700${Tff7b72thisTb4b4b4.Te6edf3javaClassTb4b4b4.Te6edf3nameTffd700}Ta5d6ff)Ta5d6ff" Tb4b4b4}
Tff7b72null
Tb4b4b4}
Tff7b72?: Te6edf3run Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffrefreshGattCache: BluetoothGatt unreachable via Kable internals (Tffd700${Tff7b72thisTb4b4b4.Te6edf3javaClassTb4b4b4.Te6edf3nameTffd700}Ta5d6ff)Ta5d6ff" Tb4b4b4}
Tff7b72return Tff7b72false
Tb4b4b4}
Tff7b72return Tff7b72try Tb4b4b4{
Tff7b72val Te6edf3refreshMethod Tff7b72= Te6edf3gattTb4b4b4.Te6edf3javaClassTb4b4b4.Te6edf3getDeclaredMethodTb4b4b4(Ta5d6ff"Ta5d6ffrefreshTa5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3apply Tb4b4b4{ Te6edf3isAccessible Tff7b72= Tff7b72true Tb4b4b4}
Tff7b72val Te6edf3result Tff7b72= Te6edf3refreshMethodTb4b4b4.Te6edf3invokeTb4b4b4(Te6edf3gattTb4b4b4) Tff7b72as? Tffa657Boolean Tff7b72?: Tff7b72false
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffrefreshGattCache: refresh() returned Tffd700$Te6edf3resultTa5d6ff" Tb4b4b4}
Te6edf3result
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffrefreshGattCache: refresh() invocation failedTa5d6ff" Tb4b4b4}
Tff7b72false
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Extracts the [BluetoothGatt] from Kable's internal object graph via a 2-hop field lookup.
*
* Hop 1: `Peripheral` → field `"connection"` (`MutableStateFlow<Connection?>`) → `.value` → `Connection` Hop 2:
* `Connection` → field `"gatt"` → `BluetoothGatt`
*
* Returns `null` if either hop fails (e.g., Kable internals changed between versions).
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffReturnCountTa5d6ff"Tb4b4b4)
Tff7b72private Tff7b72fun Te6edf3PeripheralTb4b4b4.Td2a8ffextractBluetoothGattTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3BluetoothGatt? Tb4b4b4{
T8b949e// Hop 1: Read "connection" field from the concrete Peripheral class (BluetoothDeviceAndroidPeripheral)
Tff7b72val Te6edf3connectionField Tff7b72= Te6edf3readDeclaredFieldTb4b4b4(Ta5d6ff"Ta5d6ffconnectionTa5d6ff"Tb4b4b4) Tff7b72?: Tff7b72return Tff7b72null
Tff7b72val Te6edf3connectionStateFlow Tff7b72= Te6edf3connectionField Tff7b72as? Te6edf3StateFlowTff7b72<Tff7b72*Tff7b72> Tff7b72?: Tff7b72return Tff7b72null
Tff7b72val Te6edf3connection Tff7b72= Te6edf3connectionStateFlowTb4b4b4.Te6edf3value Tff7b72?: Tff7b72return Tff7b72null

T8b949e// Hop 2: Read "gatt" field from the Connection class
Tff7b72return Te6edf3connectionTb4b4b4.Te6edf3readDeclaredFieldAsTff7b72<Te6edf3BluetoothGattTff7b72>Tb4b4b4(Ta5d6ff"Ta5d6ffgattTa5d6ff"Tb4b4b4)
Tb4b4b4}

Tff7b72private Tff7b72fun Te6edf3AnyTb4b4b4.Td2a8ffreadDeclaredFieldTb4b4b4(Te6edf3nameTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657Any? Tb4b4b4{
Tff7b72var Te6edf3clazzTb4b4b4: Te6edf3ClassTff7b72<Tff7b72*Tff7b72>Tff7b72? Tff7b72= Te6edf3javaClass
Tff7b72while Tb4b4b4(Te6edf3clazz Tff7b72!Tff7b72= Tff7b72null Tff7b72&Tff7b72& Te6edf3clazz Tff7b72!Tff7b72= Tffa657AnyTff7b72::Te6edf3classTb4b4b4.Te6edf3javaTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Tff7b72val Te6edf3field Tff7b72= Te6edf3clazzTb4b4b4.Te6edf3getDeclaredFieldTb4b4b4(Te6edf3nameTb4b4b4)
Te6edf3fieldTb4b4b4.Te6edf3isAccessible Tff7b72= Tff7b72true
Tff7b72return Te6edf3fieldTb4b4b4.Te6edf3getTb4b4b4(Tff7b72thisTb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3_Tb4b4b4: Te6edf3NoSuchFieldExceptionTb4b4b4) Tb4b4b4{
Te6edf3clazz Tff7b72= Te6edf3clazzTb4b4b4.Te6edf3superclass
Tb4b4b4}
Tb4b4b4}
Tff7b72return Tff7b72null
Tb4b4b4}

Tff7b72private Tff7b72inline Tff7b72fun Tff7b72<Tff7b72reified Te6edf3TTff7b72> Te6edf3AnyTb4b4b4.Td2a8ffreadDeclaredFieldAsTb4b4b4(Te6edf3nameTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Te6edf3T? Tff7b72= Te6edf3readDeclaredFieldTb4b4b4(Te6edf3nameTb4b4b4) Tff7b72as? Te6edf3T

Served by rngit 1.5.0 - Generated in 0.05s